<?php

/**
* @file
* Contains \Drupal\discogs\Form\SettingsForm.
*/

namespace Drupal\discogs\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
* Configure Database Source of discogs
*/
class SettingsForm extends ConfigFormBase {
	/**
	* {@inheritdoc}
	*/
	public function getFormId() {
		return 'discogs_settings';
	}
	
	/**
	* {@inheritdoc}
	*/
	protected function getEditableConfigNames() {
		return ['discogs.api'];
	}
	
	/**
	* {@inheritdoc}
	*/
	public function buildForm(array $form, FormStateInterface $form_state) {
		$discogs_defaults = $this->config('discogs.api');
		$form=[];
		$form['consumerkey']=array(
			'#type' => 'textfield',
			'#title' => $this->t('Consumer Key'),
			'#default_value' => empty($discogs_defaults->get('consumerkey'))?'':$discogs_defaults->get('consumerkey'),
			'#required' => TRUE,
		);
		$form['consumersecret']=array(
			'#type' => 'textfield',
			'#title' => $this->t('Consumer Secret'),
			'#default_value' => empty($discogs_defaults->get('consumersecret'))?'':$discogs_defaults->get('consumersecret'),
			'#required' => TRUE,
		);

		return parent::buildForm($form, $form_state);
	}

	/**
	* {@inheritdoc}
	*/
	public function validateForm(array &$form, FormStateInterface $form_state) {
	}

	/**
	* {@inheritdoc}
	*/
	public function submitForm(array &$form, FormStateInterface $form_state) {
		$this->config('discogs.api')
			->set('consumerkey', $form_state->getValue('consumerkey'))
			->set('consumersecret', $form_state->getValue('consumersecret'))
			->save();
		
		parent::submitForm($form, $form_state);
	}
}
?>

